package com.zzty.txj.serviceImpl;

import com.alibaba.fastjson.JSONObject;
import com.zzty.txj.entity.User;
import com.zzty.txj.service.UserService;
import com.zzty.txj.util.HttpUtil;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Value("${url.user.getUserById}")
    String url1;

    @Value("${url.user.getUserByOpenId}")
    String url;

//    @Value("${url.user.getUsersByClazzId}")
//    String url2;

    @Override
        public User getUserById(Integer id){
            User user = null;
        String result = null;
        try {
            result = HttpUtil.httpGet(url1 + id);
            user=JSONObject.parseObject(result,User.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
            return user;
    }

    @Override
    public User getUserByOpenId(String openId) {
        logger.info("USI getUserByOpenId openId: "+openId);

        User user=null;
        try{
            String result=HttpUtil.httpGet(url+openId);
            user=JSONObject.parseObject(result,User.class);
        }catch (Exception e){
            e.printStackTrace();
        }
        return user;
    }

//    @Override
//    public List<User> getUsersByClazzId(Integer clazzId) {
//        List<User> users=null;
//        try{
//            String result=HttpUtil.httpGet(url2+clazzId);
//            users=JSONObject.parseObject(result,List<User>.class);
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        return users;
//    }


}
